package com.sso.managedBean;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.user.util.Browser;

import com.base.commons.SpringBeanHolder;
import com.sso.entity.DicSystemUser;
import com.sso.service.IDicSystemUserService;
@ManagedBean(name = "sso_editUserBean", scope = ManagedBeanScope.REQUEST)
public class EditUserBean {

protected IDicSystemUserService dicSystemUserService = SpringBeanHolder
.getBean("dicSystemUserService");

@Bind
@Accessible
@SaveState
String id;
@Bind
@Accessible
@SaveState
protected String userID;
protected DicSystemUser user;
// 系统用户名称
@Bind(id = "userName", attribute = "value")
protected String userName;
// 密码
@Bind(id = "userPassword", attribute = "value")
protected String userPassword;

@Inject
private FacesContext context;

@SaveState
private String first;

@BeforeRender
public void beforeRender(boolean isPostBack) throws Exception {
	if (!isPostBack) {
		id = context.getExternalContext().getRequestParameterMap()
				.get("id");
		if (!"".equals(id) && null != id) {
			user = dicSystemUserService.getByUserID(id);
			if (user != null) {
				userID = user.getId();
				userName = user.getUserName();
				userPassword = user.getUserPassword();
			}
		}
	}
}

@Action(id = "save")
public void save() {
	user = dicSystemUserService.getByUserID(userID);
	user.setId(userID);
	user.setUserName(userName);
	user.setUserPassword(userPassword);
	dicSystemUserService.saveDicSystemUser(user);
	Browser
			.execClientScript("javascript:closeCenterLayoutTab('eidtUserTab')");
}
}
